﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Diagnostics;
using Merge_Sort;


namespace Gui
{
    class MergeSortOption : MenuItem
    {

        public MergeSortOption(string MenuText)
            : base(MenuText)
        {

        }
        public override void Execute()
        {
            Console.WriteLine("Sequential MergeSort of varying Array Sizes");
            for (int size = 10000000; size < 41000000; size = size + 10000000)
            {
                int[] array = MethodLibrary.GenerateArray(1, 500, size);
                /*
            
                for (int i = 1; i < array.Length; i++)
                {
                    Console.Write(b.IntArray[i]+", ");
                }*/

                MergeSort m = new MergeSort(array, 0);
                // foreach(int i in m.arr)
                //   Console.Write(i+", ");
                Stopwatch sw = new Stopwatch();
                sw.Start();
                m.seqSort();
                sw.Stop();

                Console.WriteLine("ArraySize: " + array.Length + " - Time taken: " + (double)sw.ElapsedMilliseconds / 1000);
            }
            Console.WriteLine();
            Console.WriteLine("Parallel MergeSort of varying Array Sizes and different levels of parallelism");
            /*Console.Write("size of array: ");
            
            int size = Convert.ToInt32(Console.ReadLine());
            Console.Write("Paralell tree limit: ");
            int limit = Convert.ToInt32(Console.ReadLine());*/
            for (int limit = 1; limit < 31; limit++)
            {
                for (int size = 10000000; size < 41000000; size = size + 10000000)
                {
                    int[] array = MethodLibrary.GenerateArray(1, 500, size);
                    /*
            
                    for (int i = 1; i < array.Length; i++)
                    {
                        Console.Write(b.IntArray[i]+", ");
                    }*/

                    MergeSort m = new MergeSort(array, limit);
                    // foreach(int i in m.arr)
                    //   Console.Write(i+", ");
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    m.parSort();
                    sw.Stop();

                    Console.WriteLine("ArraySize: " + array.Length + " - Tree Level: " + limit + " - Time taken: " + (double)sw.ElapsedMilliseconds / 1000);
                }
            }
            //foreach (int i in m.arr)
              //  Console.Write(i + ", ");
            
            
        }
    }
}
